
    /*
    * 参数说明
    * packetFlag   红包是否点击状态,初始－0 点击后自增
    * picState     图片点击后状态   控制其他聊天暂停播放
    */

var timepriod=0
    ,timestart=0
    ,timeend=0
    ,end=false
    ,doing=false
    ,time1
    ,time2
    ,time3
    ,time4
    ,time5
    ,time6
    ,time7
    ,time8
    ,isView=false;

var App=function(){
    var packetFlag=0
        ,winH=document.documentElement.clientHeight
        ,myScroll = new IScroll('.page4-list', { mouseWheel: true})
        ,_figer= 1
        ,_self=this;


    return{
        init:function(){

            var self=this;

            //首屏消息显示
            setTimeout(function(){
                $(".msg").addClass("show");
            }, 300);

            // 滑动
            window.pageSlide = new mo.Slide({
                target: $('#container .content .page'),
                direction: 'x',
                playTo: 1,
                disable: 2

            });

            pageSlide.on('beforechange', function(e) {
                if (e.target.curPage === 2 && e.target.oriPrevPage === 1){ // not allow slide to 2 by user
                    console.log(e);
                    pageSlide.playTo(1);
                    return false;
                }


                if(this.curPage==3){
                    if(isView==false){
                        isView=true;
                        App.pageList();
                    }else{
                        self.chatView();
                    }

                }



                if (this.curPage === 2) {
                    $('.figer1').addClass('figer-ani');

                } else {

                }
            });
            pageSlide.on('touchstart', function(){
                if(this.curPage == 3) {
                    return false;
                }
            });

            pageSlide.on('change',function(e){
                if(e.target.curPage === 0) {
                    pageSlide.playTo(2);
                }
            });

            //点同意跳转到第三屏

            $(".friend-list li").on("click touchend", function(){
                pageSlide.playTo(3);
                $(".page3").addClass("viewed");
                pageSlide.disable(3);
                $(this).removeClass('hi-light');
                $(this).find('.ui-btn').attr('class','txt-btn').html('已同意');

            });


            //好友列表提示动画

            $('.page3 .figer').on('webkitAnimationEnd', function() {
                var that=this;
                var _index=$(this).data('index');
                _figer++;
                $('.figer'+_index).fadeOut(300,function(){
                    $('.figer'+_index).remove();
                });
                if(_figer<=4){
                    setTimeout(function(){
                        $('.figer'+_figer).addClass('figer-ani');
                    },30)
                }else{
                    $('.figer'+_index).fadeOut(500);
                }

            })


            //打开红包

            $('.type-packet .list-info').tap(function(){
                var that=this,res=[],objLoader=$('.ui-loading-block');
                res.push('../img/page4/hongbao_big.png');
                objLoader.addClass('show');
                new mo.Loader(res,{
                    loadType : 1,
                    minTime : 300,
                    onComplete : function(time){
                        objLoader.removeClass('show');
                        $('.page4').addClass('blur');
                        $('#page-dialog2').addClass('show');
                        packetFlag++;


                    }
                })
            })

            //关闭红包

            $('.page-dialog-close').tap(function(){
                $('.page4').removeClass('blur');
                $('.page-dialog').removeClass('show');
                if(packetFlag==1){
                    setTimeout(function(){
                        $('.page4 li').eq(9).show();
                        self.goTop($('.page4 li').eq(9));

                    },500)
                    setTimeout(function(){
                        $('.page4 li').eq(10).show();
                        self.goTop($('.page4 li').eq(10));
                        myScroll.refresh();

                    },2500)
                }

            })

            //图片点击

            $('.type-img .list-info').tap(function(){
                var that=this
                    ,data=$(this).find('img').data('src')
                    ,objLoader=$('.ui-loading-block')
                    ,res=[];
                res.push(data);
                objLoader.addClass('show');
                self.clearQueue();
                //禁止滑屏
                new mo.Loader(res,{
                    loadType : 1,
                    minTime : 300,
                    onComplete : function(time){
                        objLoader.removeClass('show');
                        $('#page-dialog1').find('img').attr('src',data);
                        $('#page-dialog1').addClass('show');
                        $(that).find('.figer').fadeOut(function(){
                            $(that).find('.figer').remove();
                        });


                    }
                })


            })


            //图片关闭

            $('#page-dialog1').tap(function(){
                $(this).removeClass('show');
                self.autoSendMsg();
            })

            //红包链接

            $(".page-dialog .other-text").click(function(){
                $(".page-dialog").removeClass("show");
                $('.page4').removeClass('blur');
                pageSlide.playTo(2);
            });


        },
        goTop : function(obj){
            var offsetTop=obj.position().top;
            var offsetHeight=obj.offset().height;
            var ulTop=$(".page4-ul").position().top;

            var scrollTop=offsetTop+ulTop-winH+offsetHeight;


            if(scrollTop<0){
                scrollTop=0;
            }
            myScroll.scrollTo(0,-scrollTop);
            myScroll.refresh();
        },
        autoSendMsg : function(){
            var that=this;
            var times=[2000,3500,6500,8000,11000,12500,15500,17000];
            if(!end&!doing){
                timestart=new Date();
                doing=true;

                if(times[0]-timepriod>0){
                    time1=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(1));
                    },times[0]-timepriod)
                }
                //img-1
                if(times[1]-timepriod>0){
                    time2=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(2));
                    },times[1]-timepriod)
                }
                //===>2
                if(times[2]-timepriod>0){
                    time3=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(3));
                    },times[2]-timepriod)
                }
                //img-3
                if(times[3]-timepriod>0){
                    time4=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(4));
                    },times[3]-timepriod)
                }

                //===>4
                if(times[4]-timepriod>0){
                    time5=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(5));
                    },times[4]-timepriod)
                }
                //img-5
                if(times[5]-timepriod>0){
                    time6=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(6));
                    },times[5]-timepriod)
                }

                //===>6
                if(times[6]-timepriod>0){
                    time7=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(7));
                    },times[6]-timepriod)
                }

                if(times[7]-timepriod>0){
                    time8=setTimeout(function(){
                        that.sendMsg($('.page4 li').eq(8));
                    },times[7]-timepriod)
                }

            }
        },
        sendMsg : function(dom,time){

            var _self=this;
            dom.show();
            _self.goTop(dom);

        },
        clearQueue : function(){

            clearTimeout(time1);
            clearTimeout(time2);
            clearTimeout(time3);
            clearTimeout(time4);
            clearTimeout(time5);
            clearTimeout(time6);
            clearTimeout(time7);
            clearTimeout(time8);
            timeend=new Date();
            if(doing){
                timepriod+=timeend-timestart;
            }

            doing=false;


        },
        pageList : function(){
            var that=this;

            setTimeout(function(){
                $('.page4 li').eq(0).show();
                that.goTop($('.page4 li').eq(0));

            },700)

            that.autoSendMsg();

            $('.type-img .figer').addClass('figer-ani');
        },
        chatView : function(){//直接显示聊天内容接口
            var self=this;
            self.clearQueue();
            $('.page4 li').show();
            myScroll.refresh();
        }
    }
}(App || {});

var timerControl = {
    timeUpdate : function(){
        var date = new Date();
        var week_days = new Array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日');
        // var year_month = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
        var minutes = (date.getMinutes() < 10) ? '0' + date.getMinutes() : date.getMinutes();
        var hours = (date.getHours() < 10) ? '0' + date.getHours() : date.getHours();
        $('#phone_lock_time').html(hours + '<span>:</span>' + minutes);
        $('#phone_lock_date').html(date.getMonth() + "月" + date.getDate() + "日 " + week_days[date.getDay()]);

        setTimeout("timerControl.timeUpdate()", (1000 * (60 - date.getSeconds())));
    }
}

$(function() {

    App.init();

    timerControl.timeUpdate();

    //直接显示聊天内容

   // App.chatView();



});







